home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / actfancr.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  10KB  |  378 lines

  1. /*******************************************************************************
  2.  
  3.     actfancr - Bryan McPhail, mish@tendril.co.uk
  4.  
  5. *******************************************************************************/
  6.  
  7. #include "driver.h"
  8. #include "vidhrdw/generic.h"
  9.  
  10. static int actfancr_control_1[0x20],actfancr_control_2[0x20];
  11. unsigned char *actfancr_pf1_data,*actfancr_pf2_data,*actfancr_pf1_rowscroll_data;
  12. static struct tilemap *pf1_tilemap;
  13. static int flipscreen;
  14.  
  15.  
  16.  
  17. static UINT32 actfancr_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
  18. {
  19.     /* logical (col,row) -> memory offset */
  20.     return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0xf0) << 4);
  21. }
  22.  
  23. static void get_tile_info(int tile_index)
  24. {
  25.     int tile,color;
  26.  
  27.     tile=actfancr_pf1_data[2*tile_index]+(actfancr_pf1_data[2*tile_index+1]<<8);
  28.     color=tile >> 12;
  29.     tile=tile&0xfff;
  30.  
  31.     SET_TILE_INFO(2,tile,color)
  32. }
  33.  
  34. static UINT32 triothep_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
  35. {
  36.     /* logical (col,row) -> memory offset */
  37.     return (col & 0x0f) + ((row & 0x0f) << 4) + ((row & 0x10) << 4) + ((col & 0x10) << 5);
  38. }
  39.  
  40. static void get_trio_tile_info(int tile_index)
  41. {
  42.     int tile,color;
  43.  
  44.     tile=actfancr_pf1_data[2*tile_index]+(actfancr_pf1_data[2*tile_index+1]<<8);
  45.     color=tile >> 12;
  46.     tile=tile&0xfff;
  47.  
  48.     SET_TILE_INFO(2,tile,color)
  49. }
  50.  
  51. /******************************************************************************/
  52.  
  53. int actfancr_vh_start (void)
  54. {
  55.     pf1_tilemap = tilemap_create(get_tile_info,actfancr_scan,TILEMAP_OPAQUE,16,16,256,16);
  56.  
  57.     if (!pf1_tilemap)
  58.         return 1;
  59.  
  60.     return 0;
  61. }
  62.  
  63. int triothep_vh_start (void)
  64. {
  65.     pf1_tilemap = tilemap_create(get_trio_tile_info,triothep_scan,TILEMAP_OPAQUE,16,16,32,32);
  66.  
  67.     if (!pf1_tilemap)
  68.         return 1;
  69.  
  70.     return 0;
  71. }
  72.  
  73. /******************************************************************************/
  74.  
  75. WRITE_HANDLER( actfancr_pf1_control_w )
  76. {
  77.     actfancr_control_1[offset]=data;
  78. }
  79.  
  80. WRITE_HANDLER( actfancr_pf2_control_w )
  81. {
  82.     actfancr_control_2[offset]=data;
  83. }
  84.  
  85. WRITE_HANDLER( actfancr_pf1_data_w )
  86. {
  87.     actfancr_pf1_data[offset]=data;
  88.     tilemap_mark_tile_dirty(pf1_tilemap,offset/2);
  89. }
  90.  
  91. READ_HANDLER( actfancr_pf1_data_r )
  92. {
  93.     return actfancr_pf1_data[offset];
  94. }
  95.  
  96. WRITE_HANDLER( actfancr_pf2_data_w )
  97. {
  98.     actfancr_pf2_data[offset]=data;
  99. }
  100.  
  101. READ_HANDLER( actfancr_pf2_data_r )
  102. {
  103.     return actfancr_pf2_data[offset];
  104. }
  105.  
  106. /******************************************************************************/
  107.  
  108. void actfancr_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  109. {
  110.     int my,mx,offs,color,tile,pal_base,colmask[16],i,mult;
  111.     int scrollx=(actfancr_control_1[0x10]+(actfancr_control_1[0x11]<<8));
  112.     int scrolly=(actfancr_control_1[0x12]+(actfancr_control_1[0x13]<<8));
  113.  
  114.     /* Draw playfield */
  115.     flipscreen=actfancr_control_2[0]&0x80;
  116.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  117.  
  118.     tilemap_set_scrollx( pf1_tilemap,0, scrollx );
  119.     tilemap_set_scrolly( pf1_tilemap,0, scrolly );
  120.  
  121.     tilemap_update(pf1_tilemap);
  122.  
  123.     palette_init_used_colors();
  124.     pal_base = Machine->drv->gfxdecodeinfo[0].color_codes_start;
  125.     for (color = 0;color < 16;color++) colmask[color] = 0;
  126.     for (offs = 0; offs < 0x800; offs += 2)
  127.     {
  128.         tile = actfancr_pf2_data[offs]+(actfancr_pf2_data[offs+1]<<8);
  129.         colmask[tile>>12] |= Machine->gfx[0]->pen_usage[tile&0xfff];
  130.     }
  131.     for (color = 0;color < 16;color++)
  132.     {
  133.         if (colmask[color] & (1 << 0))
  134.             palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_TRANSPARENT;
  135.         for (i = 1;i < 16;i++)
  136.         {
  137.             if (colmask[color] & (1 << i))
  138.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  139.         }
  140.     }
  141.  
  142.     pal_base = Machine->drv->gfxdecodeinfo[1].color_codes_start;
  143.     for (color = 0;color < 16;color++) colmask[color] = 0;
  144.     for (offs = 0; offs < 0x800; offs += 2)
  145.     {
  146.         tile = buffered_spriteram[offs+2]+(buffered_spriteram[offs+3]<<8);
  147.         color=buffered_spriteram[offs+5]>>4;
  148.         colmask[color] |= Machine->gfx[1]->pen_usage[tile&0xfff];
  149.     }
  150.     for (color = 0;color < 16;color++)
  151.     {
  152.         if (colmask[color] & (1 << 0))
  153.             palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_TRANSPARENT;
  154.         for (i = 1;i < 16;i++)
  155.         {
  156.             if (colmask[color] & (1 << i))
  157.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  158.         }
  159.     }
  160.  
  161.     if (palette_recalc())
  162.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  163.  
  164.     tilemap_render(ALL_TILEMAPS);
  165.     tilemap_draw(bitmap,pf1_tilemap,0);
  166.  
  167.     /* Sprites */
  168.     for (offs = 0;offs < 0x800;offs += 8)
  169.     {
  170.         int x,y,sprite,colour,multi,fx,fy,inc,flash;
  171.  
  172.         y=buffered_spriteram[offs]+(buffered_spriteram[offs+1]<<8);
  173.          if ((y&0x8000) == 0) continue;
  174.         x = buffered_spriteram[offs+4]+(buffered_spriteram[offs+5]<<8);
  175.         colour = ((x & 0xf000) >> 12);
  176.         flash=x&0x800;
  177.         if (flash && (cpu_getcurrentframe() & 1)) continue;
  178.  
  179.         fx = y & 0x2000;
  180.         fy = y & 0x4000;
  181.         multi = (1 << ((y & 0x1800) >> 11)) - 1;    /* 1x, 2x, 4x, 8x height */
  182.  
  183.                                             /* multi = 0   1   3   7 */
  184.         sprite = buffered_spriteram[offs+2]+(buffered_spriteram[offs+3]<<8);
  185.         sprite &= 0x0fff;
  186.  
  187.         x = x & 0x01ff;
  188.         y = y & 0x01ff;
  189.         if (x >= 256) x -= 512;
  190.         if (y >= 256) y -= 512;
  191.         x = 240 - x;
  192.         y = 240 - y;
  193.  
  194.         sprite &= ~multi;
  195.         if (fy)
  196.             inc = -1;
  197.         else
  198.         {
  199.             sprite += multi;
  200.             inc = 1;
  201.         }
  202.  
  203.         if (flipscreen) {
  204.             y=240-y;
  205.             x=240-x;
  206.             if (fx) fx=0; else fx=1;
  207.             if (fy) fy=0; else fy=1;
  208.             mult=16;
  209.         }
  210.         else mult=-16;
  211.  
  212.         while (multi >= 0)
  213.         {
  214.             drawgfx(bitmap,Machine->gfx[1],
  215.                     sprite - multi * inc,
  216.                     colour,
  217.                     fx,fy,
  218.                     x,y + mult * multi,
  219.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  220.             multi--;
  221.         }
  222.     }
  223.  
  224.     /* Draw character tiles */
  225.     for (offs = 0x800 - 2;offs >= 0;offs -= 2) {
  226.         tile=actfancr_pf2_data[offs]+(actfancr_pf2_data[offs+1]<<8);
  227.         if (!tile) continue;
  228.         color=tile>>12;
  229.         tile=tile&0xfff;
  230.         mx = (offs/2) % 32;
  231.         my = (offs/2) / 32;
  232.         if (flipscreen) {mx=31-mx; my=31-my;}
  233.         drawgfx(bitmap,Machine->gfx[0],
  234.             tile,color,flipscreen,flipscreen,8*mx,8*my,
  235.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  236.     }
  237. }
  238.  
  239. void triothep_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  240. {
  241.     int my,mx,offs,color,tile,pal_base,colmask[16],i,mult;
  242.     int scrollx=(actfancr_control_1[0x10]+(actfancr_control_1[0x11]<<8));
  243.     int scrolly=(actfancr_control_1[0x12]+(actfancr_control_1[0x13]<<8));
  244.  
  245.     /* Draw playfield */
  246.     flipscreen=actfancr_control_2[0]&0x80;
  247.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  248.  
  249.     if (actfancr_control_2[0]&0x4) {
  250.         tilemap_set_scroll_rows(pf1_tilemap,32);
  251.         tilemap_set_scrolly( pf1_tilemap,0, scrolly );
  252.         for (i=0; i<32; i++)
  253.             tilemap_set_scrollx( pf1_tilemap,i, scrollx+(actfancr_pf1_rowscroll_data[i*2] | actfancr_pf1_rowscroll_data[i*2+1]<<8) );
  254.     }
  255.     else {
  256.         tilemap_set_scroll_rows(pf1_tilemap,1);
  257.         tilemap_set_scrollx( pf1_tilemap,0, scrollx );
  258.         tilemap_set_scrolly( pf1_tilemap,0, scrolly );
  259.     }
  260.  
  261.     tilemap_update(pf1_tilemap);
  262.  
  263.     palette_init_used_colors();
  264.     pal_base = Machine->drv->gfxdecodeinfo[0].color_codes_start;
  265.     for (color = 0;color < 16;color++) colmask[color] = 0;
  266.     for (offs = 0; offs < 0x800; offs += 2)
  267.     {
  268.         tile = actfancr_pf2_data[offs]+(actfancr_pf2_data[offs+1]<<8);
  269.         colmask[tile>>12] |= Machine->gfx[0]->pen_usage[tile&0xfff];
  270.     }
  271.     for (color = 0;color < 16;color++)
  272.     {
  273.         if (colmask[color] & (1 << 0))
  274.             palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_TRANSPARENT;
  275.         for (i = 1;i < 16;i++)
  276.         {
  277.             if (colmask[color] & (1 << i))
  278.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  279.         }
  280.     }
  281.  
  282.     pal_base = Machine->drv->gfxdecodeinfo[1].color_codes_start;
  283.     for (color = 0;color < 16;color++) colmask[color] = 0;
  284.     for (offs = 0; offs < 0x800; offs += 2)
  285.     {
  286.         tile = buffered_spriteram[offs+2]+(buffered_spriteram[offs+3]<<8);
  287.         color= buffered_spriteram[offs+5]>>4;
  288.         colmask[color] |= Machine->gfx[1]->pen_usage[tile&0xfff];
  289.     }
  290.     for (color = 0;color < 16;color++)
  291.     {
  292.         if (colmask[color] & (1 << 0))
  293.             palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_TRANSPARENT;
  294.         for (i = 1;i < 16;i++)
  295.         {
  296.             if (colmask[color] & (1 << i))
  297.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  298.         }
  299.     }
  300.  
  301.     if (palette_recalc())
  302.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  303.  
  304.     tilemap_render(ALL_TILEMAPS);
  305.     tilemap_draw(bitmap,pf1_tilemap,0);
  306.  
  307.     /* Sprites */
  308.     for (offs = 0;offs < 0x800;offs += 8)
  309.     {
  310.         int x,y,sprite,colour,multi,fx,fy,inc,flash;
  311.  
  312.         y=buffered_spriteram[offs]+(buffered_spriteram[offs+1]<<8);
  313.          if ((y&0x8000) == 0) continue;
  314.         x = buffered_spriteram[offs+4]+(buffered_spriteram[offs+5]<<8);
  315.         colour = ((x & 0xf000) >> 12);
  316.         flash=x&0x800;
  317.         if (flash && (cpu_getcurrentframe() & 1)) continue;
  318.  
  319.         fx = y & 0x2000;
  320.         fy = y & 0x4000;
  321.         multi = (1 << ((y & 0x1800) >> 11)) - 1;    /* 1x, 2x, 4x, 8x height */
  322.  
  323.                                             /* multi = 0   1   3   7 */
  324.         sprite = buffered_spriteram[offs+2]+(buffered_spriteram[offs+3]<<8);
  325.         sprite &= 0x0fff;
  326.  
  327.         x = x & 0x01ff;
  328.         y = y & 0x01ff;
  329.         if (x >= 256) x -= 512;
  330.         if (y >= 256) y -= 512;
  331.         x = 240 - x;
  332.         y = 240 - y;
  333.  
  334.         sprite &= ~multi;
  335.         if (fy)
  336.             inc = -1;
  337.         else
  338.         {
  339.             sprite += multi;
  340.             inc = 1;
  341.         }
  342.  
  343.         if (flipscreen) {
  344.             y=240-y;
  345.             x=240-x;
  346.             if (fx) fx=0; else fx=1;
  347.             if (fy) fy=0; else fy=1;
  348.             mult=16;
  349.         }
  350.         else mult=-16;
  351.  
  352.         while (multi >= 0)
  353.         {
  354.             drawgfx(bitmap,Machine->gfx[1],
  355.                     sprite - multi * inc,
  356.                     colour,
  357.                     fx,fy,
  358.                     x,y + mult * multi,
  359.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  360.             multi--;
  361.         }
  362.     }
  363.  
  364.     /* Draw character tiles */
  365.     for (offs = 0x800 - 2;offs >= 0;offs -= 2) {
  366.         tile=actfancr_pf2_data[offs]+(actfancr_pf2_data[offs+1]<<8);
  367.         if (!tile) continue;
  368.         color=tile>>12;
  369.         tile=tile&0xfff;
  370.         mx = (offs/2) % 32;
  371.         my = (offs/2) / 32;
  372.         if (flipscreen) {mx=31-mx; my=31-my;}
  373.         drawgfx(bitmap,Machine->gfx[0],
  374.             tile,color,flipscreen,flipscreen,8*mx,8*my,
  375.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  376.     }
  377. }
  378.